utils.js ➔ getRegion   C
last analyzed

Complexity

Conditions 12
Paths 12

Size

Total Lines 39

Duplication

Lines 39
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 12
c 1
b 0
f 0
nc 12
nop 1
dl 39
loc 39
rs 5.1612

How to fix   Complexity   

Complexity

Complex classes like utils.js ➔ getRegion often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1 View Code Duplication
import { RegionDomains } from './regions';
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
import * as https from 'https';
3
export function getJSON(url, callback) {
4
    https.get(url, function (res) {
5
        var statusCode = res.statusCode;
6
        if (statusCode !== 200) {
7
            res.resume();
8
            callback(null, 'error');
9
        }
10
        res.setEncoding('utf8');
11
        var rawData = '';
12
        res.on('data', function (chunk) { rawData += chunk; });
13
        res.on('end', function () {
14
            try {
15
                var parsedData = JSON.parse(rawData);
16
                callback({ headers: res.headers, statusCode: res.statusCode, data: parsedData });
17
            }
18
            catch (e) {
19
                callback(null, e);
20
            }
21
        });
22
    }).on('error', function (e) {
23
        callback(null, e);
24
    });
25
}
26
export function getRegion(region) {
27
    var val;
28
    switch (region.toUpperCase()) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
29
        case 'EUNE':
30
            val = RegionDomains.EUNE;
31
            break;
32
        case 'EUW':
33
            val = RegionDomains.EUW;
34
            break;
35
        case 'OCE':
36
            val = RegionDomains.OCE;
37
            break;
38
        case 'LAN':
39
            val = RegionDomains.LAN;
40
            break;
41
        case 'LAS':
42
            val = RegionDomains.LAS;
43
            break;
44
        case 'RU':
45
            val = RegionDomains.RU;
46
            break;
47
        case 'BR':
48
            val = RegionDomains.BR;
49
            break;
50
        case 'TR':
51
            val = RegionDomains.TR;
52
            break;
53
        case 'NA':
54
            val = RegionDomains.NA;
55
            break;
56
        case 'KR':
57
            val = RegionDomains.KR;
58
            break;
59
        case 'JP':
60
            val = RegionDomains.JP;
61
            break;
62
    }
63
    return val;
0 ignored issues
show
Bug introduced by
The variable val seems to not be initialized for all possible execution paths.
Loading history...
64
}
65
//# sourceMappingURL=utils.js.map